package edu.model;

import java.util.Date;
import java.util.Vector;

import edu.conexion.AccesoDatos;

public class Ventas {
	
	double nClaveV;
	double nClaveU;
	double nClaveR;
	double cantidad;
	double monto;
	double total;
	String snombreRev;
	
	public double getnClaveV() {
		return nClaveV;
	}
	public void setnClaveV(double nClaveV) {
		this.nClaveV = nClaveV;
	}
	public double getnClaveU() {
		return nClaveU;
	}
	public void setnClaveU(double nClaveU) {
		this.nClaveU = nClaveU;
	}
	public double getnClaveR() {
		return nClaveR;
	}
	public void setnClaveR(double nClaveR) {
		this.nClaveR = nClaveR;
	}
	public double getCantidad() {
		return cantidad;
	}
	public void setCantidad(double cantidad) {
		this.cantidad = cantidad;
	}
	public double getMonto() {
		return monto;
	}
	public void setMonto(double monto) {
		this.monto = monto;
	}
	
	public double getTotal() {
		return total;
	}
	public void setTotal(double total) {
		this.total = total;
	}
	public String getSnombreRev() {
		return snombreRev;
	}
	public void setSnombreRev(String snombreRev) {
		this.snombreRev = snombreRev;
	}
	public Ventas[] cantidadProductos() throws Exception{
		StringBuffer LsSQL = new StringBuffer("");
        AccesoDatos DAL = null;
        Vector<Object> rst = null;
        Vector<Ventas> LvData = null;
        Ventas[] rows = null;
        
        LsSQL.append("select sum(v.ncantidad) as total, r.snombre");
        LsSQL.append(" from ventas as v, revista as r");
        LsSQL.append(" where v.nClaveR = r.nClaveRev");
        LsSQL.append(" group by r.snombre");
        
        DAL = new AccesoDatos();
		DAL.conectar();
		rst = DAL.ejecutarConsulta(LsSQL.toString());
		DAL.desconectar();
		
		LvData = new Vector<Ventas>();
		for (int i = 0; i < rst.size(); i++) 
		{
			Ventas row = new Ventas();
			Vector<Object> vRowTemp = (Vector)rst.elementAt(i);				
			Object ob = vRowTemp.elementAt( 0 );
			String sob = (String)ob;
			row.total 	= Double.parseDouble(sob);
			row.snombreRev  	= (String) 	vRowTemp.elementAt( 1 );
			
			LvData.addElement(row);
		}
		int LnSize = LvData.size();
		rows = new Ventas[LnSize];
		
		for (int i = 0; i < LnSize; i++) 
		{
			rows[i] = (Ventas)LvData.elementAt(i);
		}
		return rows;
		
                
	}	
	
	public static void main(String arg[]) throws Exception{
		Ventas v = new Ventas();
		Ventas[] i = v.cantidadProductos();
	
	}
}
